package com.woniuxy.carlife.controller;


import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.Result;
import com.woniuxy.carlife.carlifecommonsweb.responsetemplate.StatusCode;
import com.woniuxy.carlife.domain.ServiceRoyalty;
import com.woniuxy.carlife.param.ServiceRoyaltyParam;
import com.woniuxy.carlife.service.ServiceRoyaltyService;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * @author fx
 * @ClassName:ServiceRoyaltyController
 * @Description: 抽成规则控制类
 * @date 2021/4/6 20:00
 **/

@RestController
@RequestMapping("/serviceRoyalty")
@Api(tags = "平台抽成规则接口信息")
@Slf4j
public class ServiceRoyaltyController {

    @Resource
    private ServiceRoyaltyService service;

    /**
     * 功能描述〈制定平台抽成规则〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/8 10:02
     * @throws
     */
    @ApiOperation(value = "制定平台抽成规则",notes = "<span style='color:red;'>制定平台抽成规则</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "制定抽成规则成功"),
            @ApiResponse(code=20001,message = "制定抽成规则失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @PostMapping("/platformmanage/serviceroyalty")
    public Result saveServiceRoyalty(@RequestBody @ApiParam ServiceRoyaltyParam royaltyParam){
        log.info("saveServiceRoyalty开始:参数：{}",royaltyParam);
        if (royaltyParam.getRoyaltyRuleName().trim().length()==0||
            royaltyParam.getRoyaltyRuleName()==null||
            royaltyParam.getRoyaltyRatio().compareTo(new BigDecimal(0))==-1||
            royaltyParam.getRoyaltyRatio()==null||
            royaltyParam.getServiceCategoryId()<=0||
            royaltyParam.getServiceCategoryId()==null)
        {
            log.info("saveServiceRoyalty结束:返回：{}","传入参数错误");
            return new Result(false, StatusCode.PARAMERROR,"传入参数错误");
        }
        Boolean b = service.saveServiceRoyalty(royaltyParam);
        if (b){
            log.info("saveServiceRoyalty结束:返回：{}","制定抽成规则成功");
            return new Result(true, StatusCode.OK,"制定抽成规则成功");
        }
        log.info("saveServiceRoyalty结束:返回：{}","制定抽成规则失败");
        return new Result(false, StatusCode.ERROR,"制定抽成规则失败");
    }

    /**
     * 功能描述〈查询所有抽成规则信息〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/12 15:35
     * @throws
     */
    @ApiOperation(value = "查询所有抽成规则信息没有参数",notes = "<span style='color:red;'>查询所有抽成规则信息</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询信息成功",response = ServiceRoyalty.class),
            @ApiResponse(code=20001,message = "查询信息失败"),
            @ApiResponse(code=00000,message = "没有数据")
    })
    @GetMapping("/platformmanage/serviceroyalty")
    public Result findAllServiceRoyalty(){
        log.info("findAllServiceRoyalty开始:");
        List<ServiceRoyalty> allServiceRoyalty = service.findAllServiceRoyalty();
        if (ObjectUtils.isEmpty(allServiceRoyalty)){
            log.info("findAllServiceRoyalty结束:返回:{}","没有查到数据");
            return new Result(false, StatusCode.NULLDATA,"查询信息失败，没有查询到数据");
        }
        log.info("findAllServiceRoyalty结束:返回:{}",allServiceRoyalty);
        return new Result(true, StatusCode.OK,"查询信息成功",allServiceRoyalty);
    }

    /**
     * 功能描述〈根据类别id查询信息〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/12 15:44
     * @throws
     */
    @ApiOperation(value = "根据类别id查询信息",notes = "<span style='color:red;'>根据类别id查询信息</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "查询信息成功",response = ServiceRoyalty.class),
            @ApiResponse(code=20001,message = "查询信息失败"),
            @ApiResponse(code=30001,message = "参数错误"),
            @ApiResponse(code=00000,message = "没有数据")
    })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "categoryId",value = "服务类别id",dataType = "Integer",paramType = "query",example = "1"),
    })
    @GetMapping("/merchantmanage/serviceroyaltycid")
    public Result findServiceRoyaltyByCatagoryId(Integer categoryId){
        log.info("findServiceRoyaltyByCatagoryId开始:参数:{}",categoryId);
        if (categoryId==null||categoryId<=0){
            log.info("findServiceRoyaltyByCatagoryId结束:返回:{}","参数错误");
            return new Result(false, StatusCode.ERROR,"传入参数错误");
        }
        ServiceRoyalty serviceRoyalty = service.findServiceRoyaltyByCatagoryId(categoryId);
        if (ObjectUtils.isEmpty(serviceRoyalty)){
            log.info("findServiceRoyaltyByCatagoryId结束:返回:{}","查询信息失败");
            return new Result(false, StatusCode.NULLDATA,"查询信息失败，数据不存在");
        }
        log.info("findServiceRoyaltyByCatagoryId结束:返回:{}",serviceRoyalty);
        return new Result(true, StatusCode.OK,"查询信息成功",serviceRoyalty);
    }

    /**
     * 功能描述〈根据类别id修改抽成信息〉
     * @author:fx
     * @param: @param null:
     * @return:
     * @Date 2021/4/12 15:45
     * @throws
     */
    @ApiOperation(value = "根据类别id修改抽成信息",notes = "<span style='color:red;'>根据类别id修改抽成信息</span>")
    //@ApiResponses用于描述响应状态信息
    @ApiResponses({
            @ApiResponse(code = 20000,message = "修改抽成规则成功",response = ServiceRoyalty.class),
            @ApiResponse(code=20001,message = "修改抽成规则失败"),
            @ApiResponse(code=30001,message = "参数错误")
    })
    @PutMapping("/platformmanage/serviceroyalty")
    public Result updateServiceRoyaltyByCatagoryId(@RequestBody @ApiParam ServiceRoyaltyParam royaltyParam){
        log.info("updateServiceRoyaltyByCatagoryId开始:参数:{}",royaltyParam);
        if (royaltyParam.getRoyaltyRuleName().trim().length()==0||
                royaltyParam.getRoyaltyRuleName()==null||
                royaltyParam.getRoyaltyRatio().compareTo(new BigDecimal(0))==-1||
                royaltyParam.getRoyaltyRatio()==null||
                royaltyParam.getServiceCategoryId()<=0||
                royaltyParam.getServiceCategoryId()==null)
        {
            log.info("updateServiceRoyaltyByCatagoryId结束:返回：{}","传入参数错误");
            return new Result(false, StatusCode.PARAMERROR,"传入参数错误");
        }
        Boolean b = service.updateServiceRoyaltyByCatagoryId(royaltyParam);
        if (b){
            log.info("updateServiceRoyaltyByCatagoryId结束:返回:{}","修改抽成规则成功");
            return new Result(true, StatusCode.OK,"修改抽成规则成功");
        }
        log.info("updateServiceRoyaltyByCatagoryId结束:返回:{}","修改抽成规则失败");
        return new Result(false, StatusCode.ERROR,"修改抽成规则失败");
    }
}

